package com.gzsxy.sso.resources.cons;

/**
 * @author xiaolong
 * @version 1.0
 * @description: Http状态码枚举类
 * @date 2021/11/8 9:35
 */
public enum HttpStatus {

    OK(200,"OK","成功"),

    BAD_REQUEST(400,"Bad Request","请求错误，请修正请求"),

    UNAUTHORIZED(401,"Unauthorized","没有授权或者授权已经失效"),

    NOT_FOUND(404,"Not Found", "资源未找到"),

    GONE(410,"Gone","请求的资源不可用"),

    INTERNAL_SERVER_ERROR(500,"Internal Server Error","服务器内部错误");

    //状态代码
    private int code;

    //英文描述
    private String reasonUS;

    //中文描述
    private String reasonCN;

    private HttpStatus(int code, String reasonUS, String reasonCN){
        this.code = code;
        this.reasonUS = reasonUS;
        this.reasonCN = reasonCN;
    }

    public int getCode(){
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getReasonUS() {
        return reasonUS;
    }

    public void setReasonUS(String reasonUS) {
        this.reasonUS = reasonUS;
    }

    public String getReasonCN() {
        return reasonCN;
    }

    public void setReasonCN(String reasonCN) {
        this.reasonCN = reasonCN;
    }



    public static HttpStatus valueof(int code){
        for (HttpStatus status : values()){
            if (status.getCode() == code){
                return status;
            }
        }
        throw new IllegalArgumentException("No matching constant for ["+code+"]");
    }
}
